home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / Kant Pro source Folder / Kant Pro 1.1 ƒ / kode new / kant build meat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-19  |  6.5 KB  |  266 lines  |  [TEXT/MMCC]

  1. #include "kant build meat.h"
  2. #include "kant build gui.h"
  3. #include "kant build files.h"
  4. #include "text twiddling.h"
  5. #include "util.h"
  6. #include "graphics.h"
  7. #include "window layer.h"
  8.  
  9. Str15            gRefLeading="\p»  &";
  10. Str15            gRefClosedLeading="\p«  &";
  11. Str15            gInstantLeading="\p          ";
  12.  
  13. static    Boolean            gIsRef;
  14. static    Boolean            gRefClosed;
  15. static    unsigned long    gLastMouseUpTime=0L;
  16. static    unsigned long    gLastMouseDownTime=0L;
  17. static    Boolean            gShouldDoDoubleClick=FALSE;
  18.  
  19. void DealWithBuildMouseUp(WindowPtr theWindow, Point thePoint)
  20. {
  21.     TEHandle        hTE;
  22.     short            selStart, selEnd, newSelStart;
  23.     short            lineNum;
  24.     unsigned char    thisChar;
  25.     
  26.     gLastMouseUpTime=TickCount();
  27.     
  28.     hTE=GetWindowTE(theWindow);
  29.     
  30.     if (gShouldDoDoubleClick)
  31.     {
  32.         lineNum=CurrentLineNumber(hTE);
  33.         selStart=LineStart(hTE, lineNum);
  34.         selEnd=LineStart(hTE, lineNum+1)-1;
  35.         newSelStart=TEGetOffset(thePoint, hTE);
  36.         thisChar=(*(**hTE).hText)[newSelStart];
  37.         if ((newSelStart==selStart) && (RefHighlightedQQ(theWindow)))
  38.         {
  39.             DealWithArrowClick(theWindow, lineNum);
  40.         }
  41.         else if ((newSelStart>=selStart) && (newSelStart<=selEnd))
  42.         {    /* is double-click */
  43.             if (RefHighlightedQQ(theWindow))
  44.                 DoEditRef(theWindow);
  45.             else
  46.                 DoEditInstantiation(theWindow);
  47.         }
  48.     }
  49.     gShouldDoDoubleClick=FALSE;
  50. }
  51.  
  52. void DealWithBuildContentClick(WindowPtr theWindow, Point thePoint)
  53. {
  54.     TEHandle        hTE;
  55.     short            selStart;
  56.     short            lineNum;
  57.     
  58.     gLastMouseDownTime=TickCount();
  59.     if (gLastMouseDownTime-gLastMouseUpTime<=LMGetDoubleTime())
  60.         gShouldDoDoubleClick=TRUE;
  61.     
  62.     hTE=GetWindowTE(theWindow);
  63.     
  64.     selStart=TEGetOffset(thePoint, hTE);
  65.     if (((*(**hTE).hText)[selStart])=='\r')
  66.         selStart--;
  67.     lineNum=LineNumberFromOffset(hTE, selStart);
  68.     if (lineNum!=CurrentLineNumber(hTE))
  69.     {
  70.         HighlightLine(hTE, lineNum);
  71.         gLastMouseUpTime=0L;
  72.         gShouldDoDoubleClick=FALSE;
  73.     }
  74.     
  75.     if ((RefHighlightedQQ(theWindow)) && (selStart==LineStart(hTE, lineNum)))
  76.         DealWithArrowClick(theWindow, lineNum);
  77. }
  78.  
  79. void DealWithArrowClick(WindowPtr theWindow, short lineNum)
  80. {
  81.     TEHandle        hTE;
  82.     ControlHandle    vScrollBar;
  83.     short            selStart, selEnd;
  84.     Str255            refName;
  85.     Boolean            alreadyOpen;
  86.     unsigned char    firstCharOfLine;
  87.     
  88.     hTE=GetWindowTE(theWindow);
  89.     vScrollBar=GetWindowVScrollBar(theWindow);
  90.     selStart=LineStart(hTE, lineNum);
  91.     firstCharOfLine=(*(**hTE).hText)[selStart];
  92.     alreadyOpen=(firstCharOfLine==gRefLeading[1]);
  93.     if (CurrentLineNumber(hTE)!=lineNum)
  94.         HighlightLine(hTE, lineNum);
  95.     
  96. //    ZapDrawHook(hTE);
  97.     
  98.     if (alreadyOpen)
  99.     {
  100.         selStart=LineStart(hTE, lineNum);
  101.         selEnd=GetNextInstantiationOffset(theWindow);
  102.         TESetSelect(selStart, selStart+1, hTE);
  103.         TEDelete(hTE);
  104.         TEInsert(&gRefClosedLeading[1], 1, hTE);
  105.         selStart=LineStart(hTE, lineNum+1);
  106.         TESetSelect(selStart, selEnd, hTE);
  107.         TEDelete(hTE);
  108.         AdjustForEndScroll(vScrollBar, hTE);
  109.         HighlightLine(hTE, lineNum);
  110.         AdjustVScrollBar(vScrollBar, hTE);
  111.     }
  112.     else
  113.     {
  114.         GetHighlightedString(theWindow, refName);
  115.         selStart=LineStart(hTE, lineNum);
  116.         TESetSelect(selStart, selStart+1, hTE);
  117.         TEDelete(hTE);
  118.         TEInsert(&gRefLeading[1], 1, hTE);
  119.         selStart=LineStart(hTE, lineNum+1);
  120.         TESetSelect(selStart, selStart, hTE);
  121.         AddInstantiationsFromFile(GetWindowFS(theWindow), theWindow, refName);
  122.         AdjustForEndScroll(vScrollBar, hTE);
  123.         HighlightLine(hTE, lineNum);
  124.         AdjustVScrollBar(vScrollBar, hTE);
  125.     }
  126.     
  127. //    RestoreDrawHook(hTE);
  128.     InvalRect(&(theWindow->portRect));
  129. }
  130.  
  131. void DoShowHideAll(WindowPtr theWindow, Boolean isShow)
  132. {
  133.     TEHandle        hTE;
  134.     short            lineNum;
  135.     short            numLines;
  136.     short            selStart;
  137.     unsigned char    firstCharOfLine;
  138.     unsigned char    charToMatch;
  139.     
  140.     hTE=GetWindowTE(theWindow);
  141.     numLines=TotalNumberOfLines(hTE);
  142.     charToMatch=isShow ? gRefClosedLeading[1] : gRefLeading[1];
  143.     
  144.     lineNum=0;
  145.     while (lineNum<TotalNumberOfLines(hTE))
  146.     /* note that TotalNumberOfLines may change if we hide or show anything */
  147.     {
  148.         selStart=LineStart(hTE, lineNum);
  149.         firstCharOfLine=(*(**hTE).hText)[selStart];
  150.         if (firstCharOfLine==charToMatch)
  151.         {
  152.             DealWithArrowClick(theWindow, lineNum);
  153.             UpdateTheWindow(theWindow);
  154.         }
  155.         lineNum++;
  156.     }
  157. }
  158.  
  159. void HighlightLine(TEHandle hTE, short lineNum)
  160. {
  161.     short            startOfLine;
  162.     unsigned char    firstCharOfLine;
  163.     
  164.     startOfLine=(**hTE).lineStarts[lineNum];
  165.     firstCharOfLine=(*((**hTE).hText))[startOfLine];
  166.     gIsRef=(firstCharOfLine!=gInstantLeading[1]);
  167.     TESetSelect(startOfLine+(gIsRef ? 3 : 5), (**hTE).lineStarts[lineNum+1], hTE);
  168.     gRefClosed=gIsRef && (firstCharOfLine==gRefClosedLeading[1]);
  169. }
  170.  
  171. Boolean RefHighlightedQQ(WindowPtr theWindow)
  172. {
  173.     if (theWindow==0L)
  174.         return TRUE;
  175.     
  176.     return (AnyHighlightedQQ(theWindow)) ? gIsRef : TRUE;
  177. }
  178.  
  179. Boolean RefClosedQQ(WindowPtr theWindow)
  180. {
  181.     if (theWindow==0L)
  182.         return FALSE;
  183.     
  184.     return (AnyHighlightedQQ(theWindow)) ? gRefClosed : FALSE;
  185. }
  186.  
  187. Boolean AddNameToTE(TEHandle hTE, Str255 theName, Boolean isRef)
  188. /* returns FALSE if no room left to insert */
  189. {
  190.     long            len, leadingLen;
  191.     unsigned char    returnChar='\r';
  192.     
  193.     len=theName[0];
  194.     leadingLen=(isRef ? gRefLeading[0] : gInstantLeading[0]);
  195.     if ((**hTE).teLength+len+leadingLen+1>32767)
  196.         return FALSE;
  197.     
  198.     if (isRef)
  199.         TEInsert(&gRefLeading[1], gRefLeading[0], hTE);
  200.     else
  201.         TEInsert(&gInstantLeading[1], gInstantLeading[0], hTE);
  202.     TEInsert(&theName[1], len, hTE);
  203.     TEInsert(&returnChar, 1, hTE);
  204.     
  205.     return TRUE;
  206. }
  207.  
  208. short GetNextInstantiationOffset(WindowPtr theWindow)
  209. {
  210.     TEHandle        hTE;
  211.     short            lineNum;
  212.     
  213.     hTE=GetWindowTE(theWindow);
  214.     lineNum=CurrentLineNumber(hTE);
  215.     do {}
  216.     while ((*(**hTE).hText)[(**hTE).lineStarts[++lineNum]]==gInstantLeading[1]);
  217.     
  218.     if (((**hTE).lineStarts[lineNum])==0)
  219.         return (**hTE).teLength;
  220.     
  221.     return (**hTE).lineStarts[lineNum];
  222. }
  223.  
  224. void GetHighlightedString(WindowPtr theWindow, Str255 theStr)
  225. {
  226.     GetStringFromLine(theWindow, theStr, CurrentLineNumber(GetWindowTE(theWindow)));
  227. }
  228.  
  229. void GetStringFromLine(WindowPtr theWindow, Str255 theStr, short lineNum)
  230. {
  231.     TEHandle        hTE;
  232.     short            selStart, selEnd;
  233.     Boolean            isRef;
  234.     
  235.     hTE=GetWindowTE(theWindow);
  236.     selStart=(**hTE).lineStarts[lineNum];
  237.     selEnd=(**hTE).lineStarts[lineNum+1]-1;
  238.     isRef=((*(**hTE).hText)[selStart]!=gInstantLeading[1]);
  239.     selStart+=isRef ? gRefLeading[0] : gInstantLeading[0];
  240.     Mymemcpy((Ptr)&theStr[1], (Ptr)((unsigned long)(*(**hTE).hText)+selStart), selEnd-selStart);
  241.     theStr[0]=selEnd-selStart;
  242. }
  243.  
  244. void GetRefNameFromInstantiation(WindowPtr theWindow, Str255 refName, short *stringIndex)
  245. {
  246.     short            index;
  247.     short            lineNum;
  248.     TEHandle        hTE;
  249.     short            offset;
  250.     unsigned char    firstChar;
  251.     
  252.     hTE=GetWindowTE(theWindow);
  253.     index=0;
  254.     lineNum=CurrentLineNumber(hTE);
  255.     do
  256.     {
  257.         index++;
  258.         offset=(**hTE).lineStarts[--lineNum];
  259.         firstChar=(*((**hTE).hText))[offset];
  260.     }
  261.     while (firstChar==gInstantLeading[1]);
  262.     
  263.     GetStringFromLine(theWindow, refName, lineNum);
  264.     *stringIndex=index;
  265. }
  266.